package com.lanou.utp.controller;

import com.lanou.utp.entity.ResponseData;
import com.lanou.utp.entity.Task;
import com.lanou.utp.service.TaskService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

/**
 * @author MaQingYun
 */
@Api("任务相关的api")
@RestController
public class TaskController {

    @Resource
    private TaskService taskService;

    @PostMapping("/tasks")
    public ResponseData getTasks( @RequestBody Map<String,Integer> map){
        //TODO 需要获取当前用户的majorid
        long majorId = 1L;
        return this.taskService.getTasks(map.get("page"), map.get("size"),majorId);
    }

    @GetMapping("/teachlink/{id}/tasks")
    public ResponseData getTaskList(@PathVariable Long id,Integer page) {
        return this.taskService.getTaskList(id, page);
    }

    @ApiOperation("添加新任务")
    @PostMapping("/task")
    public ResponseData addTask(@RequestBody Task task) {
        System.out.println("task = [" + task + "]");
        Double teacherMaturityScore = task.getTeacherMaturityScore();
        Double baseMaturityScore = task.getBaseMaturityScore();
        Double checkScore = task.getCheckScore();
        Double logScore = task.getLogScore();
        Double reportScore = task.getReportScore();
        Double ordinaryScore1 = task.getOrdinaryScore1();
        Double ordinaryScore2 = task.getOrdinaryScore2();
        Double otherScore = task.getOtherScore();
        double maturityScore = teacherMaturityScore+baseMaturityScore;
        double score = checkScore+logScore+reportScore+ordinaryScore1+ordinaryScore2+otherScore;
        if (maturityScore!=100 && score !=100){
            throw new IllegalArgumentException();
        }
        this.taskService.addTask(task);
        return null;
    }





}
